package com.ldj.common;

import javax.servlet.http.HttpServletRequest;

import com.ldj.hibernate.PersionFile;
import com.ldj.hibernate.SuperviseOrgan;
import com.ldj.hibernate.SuperviseOrganDAO;
import com.ldj.hibernate.UnitUser;

public class SystemSession {
	
	public static UnitUser getUnitUserInfo(HttpServletRequest request){
		if(request.getSession().getAttribute("UnitUserInfo") != null){
			UnitUser unitInfo = (UnitUser)request.getSession().getAttribute("UnitUserInfo");
			return unitInfo;
		}else{
			return null;
		}
	}
	
	public static String getUnitUserId(HttpServletRequest request){
		if(request.getSession().getAttribute("UnitUserInfo") != null){
			UnitUser unitInfo = (UnitUser)request.getSession().getAttribute("UnitUserInfo");
			return unitInfo.getUnitUserId();
		}else{
			return null;
		}
	}
	
	public static PersionFile getSupUserInfo(HttpServletRequest request){
		if(request.getSession().getAttribute("UserInfo") != null){
			PersionFile supInfo = (PersionFile)request.getSession().getAttribute("UserInfo");
			return supInfo;
		}else{
			return null;
		}
	}
	
	public static String getSupUserId(HttpServletRequest request){
		if(request.getSession().getAttribute("UserInfo") != null){
			PersionFile supInfo = (PersionFile)request.getSession().getAttribute("UserInfo");
			return supInfo.getPerFileId();
		}else{
			return null;
		}
	}

	
	public static SuperviseOrgan getUserOrgan(HttpServletRequest request){
		PersionFile supInfo = getSupUserInfo(request);
		if(supInfo != null){
			SuperviseOrganDAO dao = new SuperviseOrganDAO(null, null);
			SuperviseOrgan organ = dao.findByAllSupOrganCode(supInfo.getPerFileOrganCode());
			return organ;
		}else
			return null;
	}
	
}
